<!--
To change this template, choose Tools | Templates
and open the template in the editor.
-->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <link rel="stylesheet" href="createroom.css" type="text/css" charset="utf-8" />
        <title>create room</title>
    </head>
    <body background="image/createroom.png" style="background-repeat: no-repeat">
        <form method="POST" name="form1">

            <div id="roomname">
                <input type="text" name="nameroom" value="" />
            </div>

            <div id="roompassword">
                <input type="password" name="roompassword" value="" size="24"/>
            </div>

            <div id="roomsub">
                <textarea name="roomsub" rows="3" cols="45">
                </textarea>
            </div>
            <div id="btcreate">
                <input type="submit" value="Create" />
            </div>
            
        </form>
            

        <div id="statuscreate">
        <?php
            $nameroom = $_POST[nameroom];
            //echo $nameroom."<br>";

            $roompassword = $_POST[roompassword];
            //echo $roompassword."<br>";

            $roomsub = $_POST[roomsub];
            //echo $roomsub."<br>";

            $roomstatus="Public";//no password
            $page=0;//not change page
            $same="not same";
 //---------increate----------------------------------------------//

            $link = mysql_connect("localhost","root","");
            mysql_select_db("ilink");

            $result = mysql_query("SELECT roomname FROM createroom WHERE roomname='$nameroom'");
            while($linex = mysql_fetch_array($result)){
                echo "Room name : ".$linex[roomname]." have already.<br>";
                $same="same";
            }


            if($nameroom!="" && $roompassword!="" && $roomsub!="" && $same=="not same"){

                $roomstatus="Private";//have password
                mysql_query("INSERT INTO createroom (roomname,roompassword,roomsubcript,roomstatus)
                    VALUES ('$nameroom','$roompassword','$roomsub','$roomstatus')");
                    echo "complete to create private room.";

                    $page=1;//page change
        }
        else if($nameroom!="" && $roompassword=="" && $roomsub!="" && $same=="not same"){

                mysql_query("INSERT INTO createroom (roomname,roompassword,roomsubcript,roomstatus)
                    VALUES ('$nameroom','$roompassword','$roomsub','$roomstatus')");
                    echo "complete to create public room.";
                    $page=1;//page change
        }
        //else if($nameroom=="" && $roompassword=="" && $roomsub=="" && $same=="same"){
                    //echo "not create pleate enter roomname and subscript.";
          else{
              echo "Not create please enter new roomname and subscript.";
        }

            mysql_close($link);
        ?>
</div>
        <script type="text/javascript">
            var jsvar=<?php echo $page; ?>;
            
            //alert(jsvar);
            if(jsvar=="1"){
                //alert("pass");
                setTimeout(function(){location.href = "http://localhost/WebiLink/roomlist.php";},1000);
            }
        </script>
        <div id="canceltxt" ><a href="roomlist.php"> cancel.</a></div>
    </body>
</html>
